Page({
  data: {
      contacts: [
          {
              id: 1,
              avatar: 'https://picsum.photos/50/50',
              name: '张三',
              phone: '13800138000'
          },
          {
              id: 2,
              avatar: 'https://picsum.photos/50/50',
              name: '李四',
              phone: '13900139000'
          }
          // 可以继续添加更多联系人
      ],
      filteredContacts: []
  },
  onLoad() {
      this.setData({
          filteredContacts: this.data.contacts
      });
  },
  onSearchInput(e) {
      const keyword = e.detail.value;
      if (keyword) {
          const filtered = this.data.contacts.filter(contact => {
              return contact.name.includes(keyword) || contact.phone.includes(keyword);
          });
          this.setData({
              filteredContacts: filtered
          });
      } else {
          this.setData({
              filteredContacts: this.data.contacts
          });
      }
  },
  onContactTap(e) {
      const contactId = e.currentTarget.dataset.id;
      // 跳转到双方聊天页面
      wx.navigateTo({
        url: `/pages/chatDetail/chatDetail?contactId=${contactId}`,
        success: function(res) {
          console.log('跳转成功', res);
        },
        fail: function(err) {
          console.error('跳转失败', err);
        }
      });
  }
});